package org.zfes.snowier.zbss.xzy.store.queue;

import java.util.Collection;
import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.concurrent.locks.StampedLock;

import com.google.common.collect.Lists;

public class PersisitBlockQueue extends LinkedBlockingQueue{
	

	 private final ReadWriteLock lock = new ReentrantReadWriteLock();
	 private final Lock readLock = lock.readLock();
	 private final Lock writeLock = lock.writeLock();
	
	 
	 public PersisitBlockQueue(){
		 super();
	 }
	public List<Object> poll(int count) {
		//long stamp = sl.readLock();
		
		try {
			this.readLock.lock();
			int i=0;
			List<Object> dataList=Lists.newArrayList();
			Object data = super.poll();
			if(data==null) {
				return dataList;
			}
			dataList.add(data);
			
			
			int coun=count-1;
			while(i < coun && data!=null) {
				data = super.poll();
				if(data!=null) {
					dataList.add(data);
				}
				i++;
			}
			return dataList;
		}finally {
			this.readLock.unlock();
		//	 sl.unlockRead(stamp);
		}
	}

	
	
	
}
